class MyApp {
    public static Instance: MyApp = null

    public net: core.NetWork
    public handle: core.IMessageHandleMgr
    public constructor() {
        console.log("Start MyApp")
        MyApp.Instance = this

        this.net = new core.NetWork()
        this.handle = new core.MessageHandleMgrBase()
        this.net.MsgHandleMgr = this.handle
        game.Instance = new game.Game()

        this.initModule()
        this.initScene()
        this.initHandle()
        this.net.OnConnect = function (net: core.NetWork) {
            game.Instance.OnConnect()
        }

        this.net.Connect("192.168.92.63", 10000)

        core.App.ResourceUtils.loadGroup("game_preload", this.onResourceLoadComplete, this.onResourceLoadProgress, this)
    }
    private initScene(): void {
        //App.SceneManager.register(SceneConsts.LOADING, new LoadingScene());
        //App.SceneManager.register(SceneConsts.GAME, new GameScene())
        //App.SceneManager.register(SceneConsts.TEST, new TestScene())
        //App.SceneManager.register(SceneConsts.FartMonkey, new FartMonkeyScene())
        TarzanScene.Init()
        EnterScene.Init()
        MineScene.Init()
    }

    private initModule(): void {
        //App.ControllerManager.register(ControllerConsts.GameMap, new GameMapController());

    }
    private initHandle(): void {
        //this.handle.RegisterEncodeDecode(Protocol.MSG_RoomUserInfo_Index, msg.MSG_RoomUserInfo.decode, msg.MSG_RoomUserInfo.encode)
        //this.handle.RegisterEncodeDecode(Protocol.MSG_LoginRequest_Index, msg.MSG_LoginRequest.decode, msg.MSG_LoginRequest.encode)
        Protocol.LoadAllProtobuf(this.handle)
        game.RegistAllHandle(this.handle)
    }

    private onResourceLoadComplete(param1: any, param2: any): void {
        console.log("onResourceLoadComplete")
        core.App.SceneManager.runScene(SceneConsts.Enter);
    }

    private onResourceLoadProgress(itemsLoaded: number, itemsTotal: number): void {
        //App.ControllerManager.applyFunc(ControllerConsts.Loading, LoadingConst.SetProgress, itemsLoaded, itemsTotal);
        console.log("onResourceLoadProgress:" + itemsLoaded + "/" + itemsTotal)
    }
}